package Tank2;

import Tank2.*;


import java.awt.*;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class GameWindow extends Frame{
	EnemyTank enemyTank1 = new EnemyTank(20,20);
	EnemyTank enemyTank2 = new EnemyTank(200,200);
	EnemyTank enemyTank3 = new EnemyTank(100,100);
	MyTank myTank = new MyTank(400,400);
	
	Tank[] tanks = new Tank[] {enemyTank1,enemyTank2,enemyTank3,myTank};


	
	public static void main(String[] args){
		GameWindow myWindow = new GameWindow();
		
		myWindow.addWindowListener(new WindowAdapter(){
			public void windowClosing(WindowEvent e){
				System.exit(0);
			}
		});
		
		myWindow.startFrame();
		
		
	}


	private void startFrame() {
		// TODO Auto-generated method stub
		this.setSize(800,600);
		this.setVisible(true);
		new PaintThread().start();
		this.addKeyListener(new KeyboardListener());
	}
	
	public void paint(Graphics g){
		for(int i = 0;i < tanks.length;i++){
			tanks[i].paint(g);
		}

	}
	

	
	class KeyboardListener extends KeyAdapter{
		public void keyPressed(KeyEvent e){
			myTank.move(e);
		}
	}
	
	
	class PaintThread extends Thread{
		public void run(){
			while(true){
				repaint();
				try {
					Thread.sleep(100);
				} catch (InterruptedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}
	}
	
	
}
